package com.xiezc.springboot_dht.util;


import com.xiezc.springboot_dht.entityx.Node;
import com.xiezc.springboot_dht.entityx.RouterTable;
import com.xiezc.springboot_dht.message.Message;
import com.xiezc.springboot_dht.model.BeString;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.net.InetSocketAddress;
import java.nio.charset.Charset;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

@Data
@Configuration
public class ConfigBean {


    private static Charset defaultCharset = Charset.forName("utf8");


    @Value("")
    private int port = 9000;
    /**
     * 从队列中获得数据的阻塞时间
     */
    private int cachePollSec = 3 * 60;
    /**
     * ｔｏｋｅｎ的时效
     */
    private int tokenLievMin = 10;

    /**
     * 每个node的超时时间的设置
     */
    private long deadNodeTimeSec = 10 * 60 * 1000;

    /**
     * 每个KBucket的最大容量
     */
    private int KBucketSize = 20;

    private int receviceDataLen = 512 * 1024;

    @Bean
    public BlockingQueue<Message> sendCache() {
        return new LinkedBlockingQueue<>();
    }


    @Bean
    public BlockingQueue<Message> recvCache() {
        return new LinkedBlockingQueue<>();
    }

    @Bean
    public RouterTable routerTable() {
        return new RouterTable();
    }

    @Bean
    public BeString thisId() {
        return new BeString(XUtil.SHA1("dhtSpider").substring(20));
    }

    @Bean
    public Node myNode(BeString thisId) {
        return Node.createNode(thisId, new InetSocketAddress("127.0.0.1", port))
    }


}
